package com.scanner.net;

import com.scanner.util.LogUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * 用于统一封装返回请求体的json格式，传入请求参数即可
 * Created by Administrator on 2017/11/14.
 */

public class RequestUtils {
    private static final MediaType MEDIA_JSON = MediaType.parse("application/json; charset=utf-8");

    public static RequestBody getRequestBody(Object obj){
        String jsonParam = "";
        if (obj != null) {
            Gson gson = new GsonBuilder().create();
            jsonParam = gson.toJson(obj);
        }
        LogUtil.w("请求参数="+jsonParam);
        RequestBody body = RequestBody.create(MEDIA_JSON,jsonParam);
        return body;
    }
}
